package server

import (
	"crypto/md5"
	"crypto/sha1"
	"crypto/sha256"
	"encoding/base64"
	"fmt"
	"io"

	"github.com/wumansgy/goEncrypt"
)

// sha1
func Msha1(data string) string {
	t := sha1.New()
	io.WriteString(t, data)
	return fmt.Sprintf("%x", t.Sum(nil))
}

// md5
func Mmd5(data string) string {
	t := md5.New()
	io.WriteString(t, data)
	return fmt.Sprintf("%x", t.Sum(nil))
}

// sha256
func Msha256(data string) string {
	t := sha256.New()
	io.WriteString(t, data)
	return fmt.Sprintf("%x", t.Sum(nil))
}

// aes加密
func MenAes(data string) string {

	aseStr := []byte(data)

	enText, _ := goEncrypt.AesCbcEncrypt(aseStr, []byte("wumansgygoaescry"), []byte("wumansgygoaescry"))

	return base64.StdEncoding.EncodeToString(enText)
}

// aes解密
func MdeAes(data string) string {

	aseStr, err1 := base64.StdEncoding.DecodeString(string(data))
	if err1 != nil {
		return ""
	}

	deText, _ := goEncrypt.AesCbcDecrypt(aseStr, []byte("wumansgygoaescry"), []byte("wumansgygoaescry"))

	return string(deText)
}
